package com.app.view.component.room.seat 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import org.component.Button;
	
	import com.peachcastle.events.SeatEvent;
	
	import com.peachcastle.core.Display;
	
	/**
	 * ...
	 * @author kevin
	 */
	public class BankerOperate extends Display
	{
		private var _seatid:int = 0;
		
		private var _bankerArea:MovieClip = null;
		private var _playrArea:MovieClip = null;
		
		private var _btnBankerStartGame:Button = null;
		
		private var _btnPK:Button = null;
		private var _btnGiveup:Button = null;
		
		public function BankerOperate(ui:MovieClip, seatid:int) 
		{
			_seatid = seatid;
			super(ui, true);
		}
		
		override protected function initialization():void 
		{
			super.initialization();
			
			_bankerArea = assest['mc_banker_area'];
			_playrArea = assest['mc_playr_area'];
			
			_btnBankerStartGame = new Button(assest['mc_banker_area']["btn_banker_startGame"]);
			_btnPK = new Button(assest['mc_playr_area']['btn_pk']);
			_btnGiveup = new Button(assest['mc_playr_area']['btn_give_up']);
		}

		public function setOperation(act:String, status:Boolean = false):void
		{
			if (status)
			{
				showAssest();
			}else 
			{
				hideAssest();
			}
			
			switch(act)
			{
				case 'startGame':
					if (status)
					{
						_playrArea.visible = false;
						_bankerArea.visible = true;
						
						_btnBankerStartGame.addEventListener(MouseEvent.CLICK, onStartGameClick);
					}else
					{
						_bankerArea.visible = false;
						_btnBankerStartGame.removeEventListener(MouseEvent.CLICK, onStartGameClick);
					}
				
					break;
				
				case 'pk':
					if (status)
					{
						_bankerArea.visible = false;
						_playrArea.visible = true;
						
						_btnPK.addEventListener(MouseEvent.CLICK, onPkClick);
						_btnGiveup.addEventListener(MouseEvent.CLICK, onGiveupClick);
					}else
					{
						_btnPK.removeEventListener(MouseEvent.CLICK, onPkClick);
						_btnGiveup.removeEventListener(MouseEvent.CLICK, onGiveupClick);
					}
					
					break;
				
				case 'init':
				default:
					_btnBankerStartGame.removeEventListener(MouseEvent.CLICK, onStartGameClick);
					_btnPK.removeEventListener(MouseEvent.CLICK, onPkClick);
					_btnGiveup.removeEventListener(MouseEvent.CLICK, onGiveupClick);
					
					break;
			}

		}
		
		private function onStartGameClick(e:MouseEvent):void
		{
			var evt:SeatEvent = new SeatEvent(SeatEvent.SEAT_START_GAME);
			evt.seatid = _seatid;
			dispatchEvent(evt);
			evt = null;
		}
		
		private function onPkClick(e:MouseEvent):void
		{
			var evt:SeatEvent = new SeatEvent(SeatEvent.START_PK);
			evt.seatid = _seatid;
			evt.state = 1;
			dispatchEvent(evt);
			evt = null;
		}
		
		private function onGiveupClick(e:MouseEvent):void
		{
			var evt:SeatEvent = new SeatEvent(SeatEvent.START_PK);
			evt.seatid = _seatid;
			evt.state = 0;
			dispatchEvent(evt);
			evt = null;
		}
	}

}